<?php

namespace App\Http\Requests\Api;

class RegisterRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        switch ($this->route()->getName()) {
            case 'register':
                return [
                    'name' => 'required|min:2|max:30|unique:users',
                    'password' => 'required|min:6|max:32|confirmed',
                    'nickname' => 'nullable|min:2|max:30',
                    'role' => 'required|in:2,3',
                ];

            default:;
        }
    }

    /**
     * 验证消息
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'name.required' => '用户名不能为空',
            'name.min' => '用户名最小长度为 2 个字符',
            'name.max' => '用户名最大长度为 30 个字符',
            'name.unique' => '用户名已经存在',
            'nickname.min' => '昵称最小长度为 2 个字符',
            'nickname.max' => '昵称最大长度为 30 个字符',
            'password.required' => '密码不能为空',
            'password.min' => '密码最小长度为 6 个字符',
            'password.max' => '密码最大长度为 32 个字符',
            'password.confirmed' => '两次密码输入不一致',
            'role.required' => '用户身份不能为空',
            'role.in' => '用户身份数据不合法',
        ];
    }
}
